declare 
	@actionvalue varchar(100),
	@actioncode varchar(100),
	@modulecode varchar(100),
	@modulevalue varchar(100)
	
--set @modulecode='2000'
--set @modulevalue='content'

declare @permitcode varchar(100)
declare @permitvalue varchar(100)

DECLARE actionCursor CURSOR FOR
SELECT modulecode FROM tb_module
open actioncursor

FETCH NEXT FROM actionCursor into @modulecode;
WHILE @@FETCH_STATUS = 0
   BEGIN

set @permitcode=@modulecode
set @permitvalue=''
set @actioncode=''

print 'if not exists(select 1 from tb_permit where permitcode='''+@permitcode+''')'
print 'begin'
print 'insert into tb_permit('
print '	permitcode,'
print '	ModuleCode,'
print '	actioncode,'
print '	permitvalue,'
print '	createdate,'
print '	createby,'
print '	updatedate,'
print '	updateby'
print ')'
print 'values('
print ''''+	@permitcode+''','
print ''''+	@modulecode+''','
print ''''+	@actioncode+''','
print ''''+	@permitvalue+''','
print '	getdate(),'
print '	''kevin'','
print '	getdate(),'
print '	''kevin'''
print ')'
print 'end'

FETCH NEXT FROM actionCursor into @modulecode;
   END;
CLOSE actionCursor;
DEALLOCATE actionCursor;